# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

  include AuthenticatedSystem
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  ActiveScaffold.set_defaults do |config|
    config.ignore_columns.add [:created_at, :updated_at]
    config.security.current_user_method = :current_user
  end

  helper_method :current_user
  helper_method :detect_role

 private

  def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
  end

  def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.record
  end

  def detect_role id_roli
    return current_user_session.record.roles.detect { |role| role.id == id_roli }
  end

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end
